import React, { useEffect, useState } from "react";
import { message } from "antd";

/**
 * message interface
 */
interface MessageProp {
  message: string;
  instituteName?: string;
}

/**
 * MessageComp for message
 * @param props {MessageProp}
 * @constructor
 */
const MessageComp: React.FC<MessageProp> = (props: MessageProp) => {
  const [messageApi, contextHolder] = message.useMessage();
  const [currentInstitute, setCurrentInstitute] = useState<string>("");

  useEffect(() => {
    messageApi.info(props.message);
    setCurrentInstitute(props.message);
  }, [props.message]);
  useEffect(() => {
    if (typeof props.instituteName === "string") {
      setCurrentInstitute(props.instituteName);
    }
  }, [props.instituteName]);
  return <>{contextHolder}</>;
};

export default MessageComp;
